package com.privatbank.servlets;

/**
 * Created by Slava on 02.08.2014.
 */

import com.privatbank.Dao.GoodDao;
import com.privatbank.constants.Constants;
import com.privatbank.tables.Good;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class CriterionListServlet extends HttpServlet {
    private GoodDao dao = null;

    @Override
    public void init() {
        dao = new GoodDao(Constants.LOGIN, Constants.PASSWORD, Constants.URL);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        init();
        //Integer categoryId=null;
        String param = req.getParameter("param");
        //Integer idManufacturer=null;
        //String storage=null;
        //Double price = null;
        //if (req.getParameter("param") != null || (!req.getParameter("param").equals(""))) {
           int categoryId = Integer.parseInt(param);
        //}


        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();
        pw.println("<B>Список производителей</B>");
        pw.println("<table border=1>");
        try {
            pw.println("<tr>");
            pw.println("<th>Model</th>");
            pw.println("<th>ID_category</th>");
            pw.println("<th>ID_manufacturer</th>");
            pw.println("<th>Storage</th>");
            pw.println("<th>Price</th>");
            pw.println("</tr>");
            List<Good> l = dao.getCriterion(categoryId);
            for (Good good : l) {
                pw.println("<tr>");
                pw.println("<td>" + good.getModel() + "</td>");
                pw.println("<td>" + good.getIdManufacturer() + "</td>");
                pw.println("<td>" + good.getStorage() + "</td>");
                pw.println("<td>" + good.getPrice() + "</td>");
                pw.println("</tr>");
            }
        } catch (Exception e) {
            throw new ServletException(e);
        }
        pw.println("</table>");

    }


}
